package com.colin.basic;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author colin
 * @create 2022-09-12 14:29
 */
public class OOMTest {

    static List<Object> list;

    public static void main(String[] args) {
        list = new ArrayList<>();
        int i = 0;
        int j = 0;
        while (true) {
            list.add(new User(i++, UUID.randomUUID().toString()));
            new User(j--, UUID.randomUUID().toString());
        }
    }
}

class User{
    int id;
    String str;

    @Override
    protected void finalize() throws Throwable {
        OOMTest.list.add(this);
        System.out.println("关闭资源，userid=" + this.getId()+ "即将被回收");
    }

    public User(int id, String str) {
        this.id = id;
        this.str = str;
    }

    public int getId() {
        return id;
    }
}
